package com.msg.controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.msg.actions.ActionHelper;
import com.msg.utils.ProjectConstants;

/**
 * Servlet implementation class XmlUploadHelper
 */
@WebServlet("/XmlUploadHelper")
public class XmlUploadHelper extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public XmlUploadHelper() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//MultipartRequest req=new MultipartRequest(request);
		
		ActionHelper actionHelper = new	ActionHelper();
		
		
			//System.out.println("Servlet called");
			/*Enumeration<String> e = request.getParameterNames();
			while(e.hasMoreElements()){
				String name = e.nextElement().toString();
				System.out.println("name: "+name+" value: "+request.getParameter(name));
			}
			*/
			ProjectConstants.xmlPath = this.getServletContext().getRealPath("/files");
			actionHelper.uploadXml(request);
			
			/*String jsonString = actionHelper.getEventData();
			response.setContentType("application/json");
			//System.out.println(jsonString);
			response.getWriter().write(jsonString);
			response.getWriter().flush();
			response.getWriter().close();*/
			 RequestDispatcher dispatcher = request.getRequestDispatcher("/index.html");
	         dispatcher.forward(request, response);
	}

}
